package cn.hongxin.sap.conn.example;

import cn.hongxin.sap.conn.dto.DemoDto;
import cn.getech.poros.framework.common.api.RestResponse;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author hengji.li@getech.cn
 * @date 2020/2/21
 */
@RestController
@RequestMapping("/demo")
@RefreshScope
@Validated
public class DemoController {

    @Value("${nacosConfig: tom}")
    private String nacosCofig;

    @Value("${sharedConfig: share}")
    private String sharedConfig;

    @Autowired
    private TestService service;


    @GetMapping("/nacos/config")
    public RestResponse nacosConfig() {
        JSONObject config = new JSONObject();
        config.put("config" , nacosCofig);
        config.put("sharedConfig" , sharedConfig);
        return RestResponse.ok(config);
    }

    @GetMapping(value = "/hello")
    public RestResponse<DemoDto> apiHello(@RequestParam @NotBlank String name) {
        return RestResponse.ok(service.sayHello(name));
    }

}
